package com.bsth.webservice.impl;

import com.bsth.webservice.TestService;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import javax.jws.WebService;
import java.util.Iterator;

@WebService(targetNamespace = "http://webservice.bsth.com/",endpointInterface = "com.bsth.webservice.TestService")
public class TestServiceImpl implements TestService {

    @Override
    public String handleDatas(String messages) {
        try {
            Document document = DocumentHelper.parseText(messages);
            Element rootElement = document.getRootElement();
            for (Iterator<Element> it = rootElement.elementIterator("info");it.hasNext();){
                Element element = it.next();
                System.out.println(element.elementText("loginname"));
                System.out.println(element.elementText("jxid"));
                System.out.println(element.elementText("idcardno"));
                System.out.println(element.elementText("state"));
                System.out.println(element.elementText("realname"));
                System.out.println(element.elementText("courseid"));
                System.out.println(element.elementText("password"));
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return messages;
    }

    public static void main(String[] args) {
        //学生
        String students = "<MessageBody type=\"student\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ><info><loginname>testguishun</loginname><jxid>10000</jxid><idcardno>310115198903227618</idcardno><state>2</state><realname>testguishun</realname><courseid>117</courseid><password>11111111</password></info></MessageBody>";
        TestServiceImpl testService = new TestServiceImpl();
        testService.handleDatas(students);
    }
}
